package com.cdm.forum.controller;

import com.cdm.forum.common.Result;
import com.cdm.forum.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@Api(tags = "测试类的相关接口")
@RequestMapping("/forum")
@RestController
public class TestForum {

    @ApiOperation("测试接口:/test, 返回\"test\"")
    @RequestMapping("/test")
    public String test() {
        return "test";
    }

    @ApiOperation("测试接口:/test, 返回name")
    @RequestMapping("/name")
    private Result show(@ApiParam("姓名") @RequestParam("name") String name) {
        return Result.success(name);
    }

    @ApiOperation("测试接口:/exception，显示Exception异常信息")
    @RequestMapping("/exception")
    public String testException() throws Exception {
        throw new Exception("这是⼀个Exception");
    }

    @ApiOperation("测试接口:/exception，显示ApplicationException异常信息")
    @RequestMapping("/appException")
    public String testApplicationException() {
        throw new ApplicationException("这是⼀个⾃定义的ApplicationException");
    }
}


